using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.IO;
using System.Windows.Forms;

namespace AppConfigEditor {
    [RunInstaller(true)]
    public partial class ConfigMgrInstaller : Installer {
        public ConfigMgrInstaller() {
            InitializeComponent();            
        }

        public override void Install(System.Collections.IDictionary stateSaver) {
            base.Install(stateSaver);
            Process();
        }
        private void Process() {
            string dir = "";
            try {
                dir = this.Context.Parameters["dir"]; //this is the value from setup project CustomActionData
                ConfigForm.ConfigForm cf = new ConfigForm.ConfigForm(dir);
                cf.ShowDialog();
                cf.Close();
            } catch (Exception ex){
                StreamWriter sw = File.CreateText(dir + "SetupLog.txt");
                sw.WriteLine("Error log: " + DateTime.Now.ToLocalTime());
                if (this.Context.Parameters.Count > 0) {
                    foreach (string s in this.Context.Parameters.Keys) {
                        sw.WriteLine("parameter: " + s + " value: " + this.Context.Parameters[s]);
                    }
                }
                sw.WriteLine(ex.Message);
                sw.Flush();
            sw.Close();
            }
        }
    }
}